<template>
	<view
	class="ln_dial"
	:style="{'width': width + 'rpx', 'height': height + 'rpx'}">
		<view
		class="ln_dial_body"
		:style="{'width': width + 'rpx', 'height': height + 'rpx'}"
		@click="dialTo">
			<slot></slot>
		</view>
	</view>
</template>

<script>
	export default {
		name: "ln_dial",
		props: {
			telephone: {
				type: String,
				default: ''
			},
			height: {
				type: Number,
				default: 100
			},
			width: {
				type: Number,
				default: 100
			}
		},
		methods: {
			// 点击拨出
			dialTo () {
			try{
				plus.android.requestPermissions(
					["android.permission.CALL_PHONE"],
					(resultObj) => {
						let result = 0;
							for (let i = 0, len = resultObj.granted.length; i < len; i++) {
							let grantedPermission = resultObj.granted[i];
							result = 1
						}
						for (let i = 0, len = resultObj.deniedPresent.length; i < len; i++) {
							let deniedPresentPermission = resultObj.deniedPresent[i];
							console.log('拒绝本次申请的权限：' + deniedPresentPermission);
							result = 0
						}
						for (let i = 0, len = resultObj.deniedAlways.length; i < len; i++) {
							let deniedAlwaysPermission = resultObj.deniedAlways[i];
							console.log('永久拒绝申请的权限：' + deniedAlwaysPermission);
							result = -1
						}
						if (result === 1) {
							// 导入Activity、Intent类
							var Intent = plus.android.importClass("android.content.Intent");  
							var Uri = plus.android.importClass("android.net.Uri");  
							// 获取主Activity对象的实例
							var main = plus.android.runtimeMainActivity();  
							// 创建Intent
							var uri = Uri.parse("tel:" + this.telephone);//这里可修改电话号码
							var call = new Intent("android.intent.action.CALL",uri);
							// 调用startActivity方法拨打电话
							plus.device.dial(this.telephone, false);
							main.startActivity(call);
						}
					},
					(error) => {
						console.log('申请权限错误：' + error.code + " = " + error.message);
					}
				)
			}catch(e){
				uni.showToast({
					title:"拨打失败",
					icon:'none'
				})
			}
				
			}
		}
	}
</script>

<style>
</style>